import type { TextProps, OptionsProps, PicLink, Status, VueComType } from '@/types'

// 题目类型
export type SurveyComName = 'single-select' | 'single-pic-select' | 'personal-info-gender' | 'personal-info-diploma'

// 业务组件类型（题目类型+非题目类型）
export type Material = SurveyComName | 'text-note'

// 编辑组件类型:集合了所有的编辑组件
export type EditComName = 'title-editor' | 'text-type-editor' | 'size-editor' | 'italic-editor' | 'weight-editor' | 'position-editor' | 'options-editor' | 'pic-options-editor' | 'text-note' | 'desc-editor' | 'italic-editor' | 'weight-editor' | 'position-editor' | 'single-pic-select' | 'single-select' | 'personal-info-gender' | 'personal-info-diploma'

// 所有的组件类型：业务组件类型 + 编辑组件类型
export type ComponentName = Material | EditComName

export type ComponentMap = {
  [key in ComponentName]: VueComType
}


export interface Actions {
  setTextStatus: (textProps: TextProps, text: string) => void
  addOption: (OptionsProps: OptionsProps) => void
  removeOption: (OptionsProps: OptionsProps, index: number) => void
  setPosition: (OptionsProps: OptionsProps, index: number) => void
  setCurrentStatus: (OptionsProps: OptionsProps, index: number) => void
  setPicLinkByIndex: (OptionsProps: OptionsProps, payload: PicLink) => void
}

// 仓库状态
export interface MaterialStore extends Actions {
  currentMaterialCom: Material
  coms: Record<Material, Status>
  setCurrentSurveyCom: (com: Material) => void
}

// 记录题目类型的数组
export const SurveyComNameArr = [
  'single-select',
  'single-pic-select',
  'personal-info-gender',
  'personal-info-diploma'
]

// 判断传入的值是否为题目类型
export function isSurveyComName(value: string): value is SurveyComName {
  return SurveyComNameArr.includes(value as SurveyComName)
}

// 该数组记录适合生成PDF的题目类型
const PDFComs = [
  'single-select',
  'single-pic-select',
  'personal-info-gender',
  'personal-info-diploma',
  'text-note'
]

export function canUsedForPDF(value: string): boolean {
  return PDFComs.includes(value)
}

export type QuizData = {
  surveyCount: number;
  coms: Status[];
};